<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
            var data = {
                key1: 'str1',
                key2: {
                    key3: 'str3',
                    key4: 'str4',
                    key5: {
                        key6: 'str6'
                    }
                }
            }
        function getKeys(data, str){
            var result = ''
            var key = Object.keys(data)
            for(var i in key){
                if(typeof(data[key[i]])=="object"){
                    var ans = getKeys(data[key[i]],str)
                    if(ans!=''){
                        result+=key[i]+ans
                    }
                }else if(data[key[i]]==str){
                    result += key[i]
                }
            }
            return result
        }
        console.log(getKeys(data,"str6"))
    </script>
</body>
</html>